package service

import DTO.FootDTO
import dao.TestDao
import domain.Foot
import spock.lang.Shared
import spock.lang.Specification

class Test extends Specification {
    @Shared
    //指明共享字段
    TestService testService;

    def setupSpec() {//初始化

    }

    def "test"() { //生命一个测试块，名字随意
        given: "准备mock数据"
        def testDao = Stub(TestDao) {
            queryUserLikeFootByUserId(1) >> [new Foot(1, 1, "汉堡", 1000), new Foot(2, 1, "炸鸡", 2000)]
        }
        testService = new TestService(testDao)
        when: "测试方法"
        def foot = testService.userLikeFoot(1)

        then: "校验结果"
        foot==([new FootDTO("汉堡",1000),new FootDTO("炸鸡",2000)])     //结果对比比的是两边调用toString()方法得到的结果。

    }

    def "test1"() { //生命一个测试块，名字随意
        given: "准备mock数据"
        def testDao = Stub(TestDao) {
            queryUserLikeFootByUserId(1) >> [new Foot(1, 1, "汉堡", 1000), new Foot(2, 1, "炸鸡", 2000)]
            queryUserLikeFootByUserId(2) >> [new Foot(3, 2, "可乐", 3000), new Foot(4, 2, "薯条", 4000)]

        }
        testService = new TestService(testDao)

        expect: "测试方法"
        foot == testService.userLikeFoot(uid,id)

        where: "校验结果"
        uid | id || foot
        1   |  0 ||([new FootDTO("汉堡",1000),new FootDTO("炸鸡",2000)])
        2   |  0 ||([new FootDTO("可乐",3000),new FootDTO("薯条",4000)])

    }
}
